function dz=renew(t,z)
%
% This function gives the differential equations in the renewable energy,
% or "backstop technology", regime where the price of renewables is still
% changing. The following regime is solved analytically.
%
global parms gamma

% Note that parms is a 1x15 vector with elements:
%
% [delta A Sbar alpha0 alpha1 alpha2 alpha3 Gamma1 H_Tbar alpha psi beta gamma Q0 popgr Abar]
%   1    2   3      4      5    6     7       8      9    10     11  12  13   14   15

delta = parms(1);
A = parms(2);

Gamma1 =parms(8);
alpha = parms(10);
psi = parms(11);
beta = parms(12);

dz = zeros(4,1);

k=z(1);
H=z(2);
lambda=z(3);
eta=z(4);

p = (Gamma1+H)^(-alpha);
c = lambda^(-1/gamma);
j = A*k*(eta*(1-psi)/lambda)^(1/psi);
i = A*k*(1-p)-c-j;

% if i<0
%     i = 0
%     j = A*k*(1-p)-c;
%
% Now evaluate the differential equations
%

dz(1) = i - delta*k;
%dz(2) = A*k*(eta*(1-psi)/lambda)^(1/psi-1);
dz(2) = j^(1-psi)*(A*k)^psi;
dz(3) = lambda*(beta+delta-A*(1-p))-psi*A*(1-psi)^(1/psi-1)*(lambda^(1-1/psi))*(eta^(1/psi));
dz(4) = beta*eta - lambda*alpha*p*A*k/(Gamma1+H);
